package site.jlopen.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import site.jlopen.entity.BaseResponse;
import site.jlopen.secret.model.job.SecretJobCreateReq;
import site.jlopen.secret.model.job.SecretJobLogResp;
import site.jlopen.service.imp.JobTaskConvertForApiService;

@RestController
@RequestMapping(value="/api/job")
public class ApiJobController {
	private final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private JobTaskConvertForApiService jobTaskService;
	
	@PostMapping(value = "/create" )
	public BaseResponse<String> create(@RequestBody SecretJobCreateReq form) {
		logger.info("任务接口调用");
		return jobTaskService.create(form); 
	}
	
	@PostMapping(value = "/start" )
	public BaseResponse<String> start(String projectCode) {
		logger.info("任务接口调用");
		return jobTaskService.start(projectCode); 
	}
	
	@PostMapping(value = "/restart" )
	public BaseResponse<String> restart(String projectCode) {
		logger.info("任务接口调用");
		return jobTaskService.restart(projectCode);
	}
	
	@PostMapping(value = "/logs" )
	public BaseResponse<SecretJobLogResp> logs(String projectCode) {
		logger.info("任务接口调用");
		return jobTaskService.logs(projectCode);
	}
	
	@PostMapping(value = "/callback" )
	public BaseResponse<String> logs(@RequestBody SecretJobLogResp resp) {
		logger.info("任务接口回调：{}", resp);
		return new BaseResponse<String>().success("回调成功");
	}
}